﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
namespace HealthSystem.sysAdmin
{
    public partial class schoolpermit : BasePage
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                choosebt.OnClientClick = Window1.GetSaveStateReference(TextBox2.ClientID)
                   + Window1.GetShowReference("./ChooseOrg.aspx");
                btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
                string id = Request["id"].ToString();
                HW_School school = manager.GetById(id);
                //bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                //if (exist)
                //{
                Bind(school);
                //}
            }
        }
        public void Bind(HW_School school)
        {
            this.name.Text = school.Name;
            this.id.Text = school.SchoollCode;

            LinkMan.Text = school.LinkMan;
            MobilePhone.Text = school.MobilePhone;
            OfficePhone.Text = school.OfficePhone;
            Address.Text = school.Address;
            SchoolType.Text = school.SchoolType;
            Email.Text = school.Email;
           // manager.ModHW_School(school);
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            string id = Request["id"].ToString();
            HW_School school = manager.GetById(id);
            bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
            if (exist)
            {
                school.Name = this.name.Text;
                school.LinkMan = LinkMan.Text;
                school.MobilePhone = MobilePhone.Text;
                school.OfficePhone = OfficePhone.Text;
                school.Address = Address.Text;
                school.SchoolType = SchoolType.Text;
                school.Email = Email.Text;
                manager.ModHW_School(school);
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            else
            {
                Alert.Show("您没有权限修改该学校");
            }
        }
        protected void Permitbt_Click(object sender, EventArgs e)
        {
            try
            {
                HW_School school = manager.GetById(Request["id"].ToString());
                bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                if (exist)
                {

                    school.Statute = "T";
                    manager.ModHW_School(school);
                }
                else
                {
                    Alert.Show("您没有权限给该用户授权");
                }
            }
            catch
            {
                Alert.Show("授权出错！");
            }
        }
    }
}